
//引入网络库
import { get, post } from "../../util/util.js"

// 获取全局应用程序实例对象
var app = getApp();

// 创建页面实例对象
Page({
  /**
   * 页面名称
   */
  name: "yirendetail",
  /**
   * 页面的初始数据
   */

  data: {
    showModal: false,
    uid: '',
    id: '',
    is_collect: 0,
    realname: '',
    sex_name: '',
    age_group_name: '',
    height_group_name: '',
    selected1: true,
    selected2: false,
    selected3: false,
    selected4: false,
    defaulImg: "http://wolaimage-10029986.image.myqcloud.com/1-2016051421050035278.png",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },

  onLoad: function (o) {
    var that = this;
    that.setData({
      uid: o.Myuid
    })
    // console.log("艺人详情数据======"+o.Touid); Myuid
    //获取剧组详情
    post("/actor/getBaseInfo", { touid: o.Touid, myuid: o.Myuid}).then(data => {
      console.log("艺人详情数据=====" + data.data.is_collect);
      that.setData({
        id: o.Touid,
        // uid: o.Myuid,
        is_collect: data.data.is_collect,
        headimg: data.data.headimg,
        bgimg: data.data.bgimg,
        realname: data.data.realname,
        sex_name: data.data.sex_name,
        age_group_name: data.data.age_group_name,
        height_group_name: data.data.height_group_name + 'cm',
        stage_name: data.data.stage_name,
        native_place: data.data.native_place,
        live_place: data.data.live_place,
        grad_school: data.data.grad_school,
        shape_group_name: data.data.shape_group_name,
        yanzhi: data.data.face_group,
        yuyan: data.data.language_group,
        biaoqian: data.data.skill_group,
        techang: data.data.feature_group,
        intro: data.data.intro,
        mobile: data.data.mobile,
        wx: data.data.wx,
        email: data.data.email,
      })
    })

    //图片
    post("/actor/getPhoto", { uid: o.Touid }).then(data => {
      that.setData({
        imgs: data.data,
      })
    })
    //视频
    post("/actor/getIntroVideo", { touid: o.Touid }).then(data => {
      that.setData({
        introVideo: data.data,
      })
    })
    //演绎经历 
    post("/actor/getExperience", { uid: o.Touid }).then(data => {
      that.setData({
        experience: data.data,
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },


  selected1: function (e) {
    this.setData({
      selected1: true,
      selected2: false,
      selected3: false,
      selected4: false
    })
  },
  selected2: function (e) {
    this.setData({
      selected2: true,
      selected1: false,
      selected3: false,
      selected4: false
    })
  },
  selected3: function (e) {
    this.setData({
      selected3: true,
      selected2: false,
      selected1: false,
      selected4: false
    })
  },
  selected4: function (e) {
    this.setData({
      selected4: true,
      selected2: false,
      selected3: false,
      selected1: false
    })
  },
  modalShare: function () {
    var that = this;
    this.setData({
      showModal: true
    })
  },
  touchCloseDialog: function () {
    var that = this;
    this.hideModal();
  },
  modalCollect: function () {
    var that = this;
    if (that.data.is_collect == 0) {
      wx.showModal({
        title: '收藏',
        content: '确定是否收藏？',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            post("/user/collect", { uid: that.data.uid, type: 3, id: that.data.id }).then(data => {
              console.log("-确定是否收藏？======" + data.data);
              that.setData({
                is_collect: 1,
              })
              wx.showToast({
                title: data.msg,
                icon: 'succes',
                duration: 1000,
                mask: true
              })
              this.setData({
                showModal: true
              })
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else if (that.data.is_collect == 1) {
      wx.showModal({
        title: '取消收藏',
        content: '是否取消收藏？',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            post("/user/uncollect", { uid: that.data.uid, type: 3, id: that.data.id }).then(data => {
              console.log("-确定是否取消收藏？======" + data.data);
              that.setData({
                is_collect: 0
              })
              wx.showToast({
                title: '已取消收藏',
                icon: 'succes',
                duration: 1000,
                mask: true
              })
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },
  onShareAppMessage: function () {
    var that = this;
    return {
      title: that.data.realname,
      desc: that.data.sex_name + that.data.age_group_name + that.data.height_group_name,
      path: '/yirendetail/yirendetail?Touid=' + that.data.id
    }
  },
  /**
     * 弹窗
     */
  showDialogBtn: function () {
    this.setData({
      showModal: true
    })
  },
  /**
   * 弹出框蒙层截断touchmove事件
   */
  preventTouchMove: function () {
  },
  /**
   * 隐藏模态对话框
   */
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  /**
   * 对话框取消按钮点击事件
   */
  onCancel: function () {
    this.hideModal();
  },
  /**
   * 对话框确认按钮点击事件
   */
  onConfirm: function () {
    var that = this;
    console.log('用户点击确定')
    this.hideModal();
    post("/pay/getPayItem", { cate: 2 }).then(data => {
      console.log("-getPayItem======" + JSON.stringify(data.data));
      post("/pay/payItem", { item_id: data.data.id, uid: that.data.uid }).then(data1 => {
        if (data1.code == 0) {
          wx.showToast({
            title: '置顶成功',
            icon: 'succes',
            duration: 1000,
            mask: true
          })
        } else if (data1.code == 4011) {
          wx.showModal({
            title: '非常抱歉',
            content: '积分不足,立即前往充值？',
            success: function (res) {
              if (res.confirm) {
                // console.log('用户点击确定')
                wx.navigateTo({
                  url: '../pay/pay?uid=' + that.data.uid,
                })
              } else {
                console.log('用户点击取消')
              }

            }
          })
        }
      })
    })
  },
  imgYu: function (event) {
    console.log('用户点击预览')
    var src = event.currentTarget.dataset.src;//获取data-src
    var imgList = [];//获取data-list
    imgList.push(src);
    //图片预览
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  }
})

